<!doctype html>
<html lang="zh-CN">
<head>
 <meta charset="UTF-8">
 <link rel="stylesheet" href="../view/admin/css/common.css">
 <link rel="stylesheet" href="../view/admin/css/main.css">
 <script type="text/javascript" src="../view/admin/js/jquery.min.js"></script>
 <script type="text/javascript" src="../view/admin/js/colResizable-1.3.min.js"></script>
 <script type="text/javascript" src="../view/admin/js/common.js"></script>
 <script type="text/javascript">
    $(function(){  
      $(".list_table").colResizable({
        liveDrag:true,
        gripInnerHtml:"<div class='grip'></div>", 
        draggingClass:"dragging", 
        minWidth:30
      }); 

    }); 
    function save(id,key){
      if(confirm("确认要提交数据吗?")){
        var re = /^-?\d+$/;
      var v = $('#a'+id+'').val();

      if(!re.test(v)){
        alert('请输入数字,不能带有空格');
        return false;
      }
        $.ajax({
          url:'./index.php?c=attendence&a=logAction',
          type:'get',
          dataType:'json',
          data:{course:$('input[id=a'+id+']').val(),id:id,key:key,bj:$('#bj').val()},
          success: function(data){
            if(data==1){
             // $('td[id='+id+']').text($('input[id=a'+id+']').val());
             alert("保存成功")
              $('input[id=a'+id+']').val($('input[id=a'+id+']').val()).css("background","lightblue").prop("readonly",true)
            }else{
              alert("保存失败")
               $('input[id=a'+id+']').val($('input[id=a'+id+']').val()).css("background","red")
            }
          }
        });
      }else{
        return false;
      }
      
    }
    function save2(id,c1,c2){
      if(confirm("确认要提交数据吗?")){
        var v1=$('#a'+id+'[name='+c1+']').val()
        var v2=$('#a'+id+'[name='+c2+']').val()

      if(v1==""){
        v1=0
      }
      if(v2==""){
        v2=0
      }

      var re = /^-?\d+$/
      if(!re.test(v1)||!re.test(v2)){
        alert('请输入数字,不能带有空格');
        return false;
      }
        $.ajax({
          url:'./index.php?c=attendence&a=logAction2',
          type:'get',
          dataType:'json',
          data:{c1:v1,c2:v2,key1:c1,key2:c2,id:id,bj:$('#bj').val()},
          success: function(data){
            if(data==1){
             // $('td[id='+id+']').text($('input[id=a'+id+']').val());
             alert("保存成功")
              $('#a'+id+'[name='+c1+']').val($('#a'+id+'[name='+c1+']').val()).css("background","lightblue").prop("readonly",true)
              $('#a'+id+'[name='+c2+']').val($('#a'+id+'[name='+c2+']').val()).css("background","lightblue").prop("readonly",true)

            }else{
              alert("保存失败")
               
               $('#a'+id+'[name='+c1+']').val($('#a'+id+'[name='+c1+']').val()).css("background","red")
               $('#a'+id+'[name='+c1+']').val($('#a'+id+'[name='+c1+']').val()).css("background","red")
            }
          }
        });
      }else{
        return false;
      }

      
    }

    function update(id,c){
      $(id).val("").css("background","").prop("readonly",false)
    }

 </script>
 <title>学生名单</title>
</head>
<body>
<div class="container" style="width:960px;margin:0 auto;">
  
  <div class="box span10 oh">
  <div class="box">
      <div class="box_border">
        <div class="box_top"><b class="pl15">学生名单</b></div>
      </div>
    </div>
  <table  border="0" cellpadding="0" cellspacing="0" class="list_table">
    <?php if(!empty($row)){?>
     <tr class="tr">
      <td class="td_center"><?php echo "编号"; ?></td>
      <td class="td_center"><?php echo $row[0]['NO']; ?></td>
      <td class="td_center"><?php echo $row[0]['name']; ?></td>
      <?php foreach ($c as $v) {?>
        <td class="td_center"><?php echo $row[0][$v]; ?></td>
      <?php  }?>
      <td class="td_center" colspan="2" style="width:180px">操作</td>
    </tr>
    <?php for($i=1;$i<count($row); $i++) {?>
     <tr class="tr">
      <td class="td_center"><?php echo $i; ?></td>
      <td class="td_center"><?php echo $row[$i]['NO']; ?></td>
      <td class="td_center"><?php echo $row[$i]['name']; ?></td>
      <?php foreach ($c as $v) {?>
        <td class="td_center" id="<?php echo $row[$i]['NO']; ?>" class="<?php echo $row[$i]['NO']; ?>">
          <input id="<?php echo "a".trim($row[$i]['NO']);?>" type="text" name="<?php echo $v;?>" class="input-text lh30">
        </td>
     <?php  }?>
     <td class="td_center" >
     <?php
     if($len==2){?>
       <a href="javascript:void(0)" onclick=" return save2(<?php echo "'".$row[$i]['NO']."'"; echo ",'".$c[$len-2]."'";echo ",'".$c[$len-1]."'";?>)"><input type="button" name="button" class="btn btn82 btn_save2" value="保存"></a>
     <?php
      }else{?>
         <a href="javascript:void(0)" onclick=" return save(<?php echo "'".$row[$i]['NO']."'"; echo ",'".$v."'";?>)"><input type="button" name="button" class="btn btn82 btn_save2" value="保存"></a>
     <?php
      }
     ?>
       
     </td>
     <td class="td_center">
       <a href="javascript:void(0)" onclick="update(<?php echo 'a'.$row[$i]['NO']?>)"><input type="button" name="button" class="btn btn82 btn_save2" value="修改"></a>
     </td>
    </tr>
    <?php 
      }
    }?>
  </table>
  <input type="hidden" id="bj" value="<?php echo $class;?>">
 </div>
  <div class="page mt10">
    <div class="pagination">
      <ul>
          <li class="first-child"><a href="#">首页</a></li>
          <li class="disabled"><span>上一页</span></li>
          <li class="active"><span>1</span></li>
          <li><a href="#">2</a></li>
          <li><a href="#">下一页</a></li>
          <li class="last-child"><a href="#">末页</a></li>
      </ul>
    </div>
  </div>
</div>
 </body>
 </html>